package cn.interestinghop.servlet;

import cn.interestinghop.model.entity.User;
import cn.interestinghop.service.user.UserService;
import cn.interestinghop.service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "AllServlet",urlPatterns = "/AllServlet")
public class AllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        UserService service = new UserServiceImpl();
        HttpSession session = request.getSession();
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        System.out.println(account+password);
        User user = service.GetAll(account,password);
       request.getSession().setAttribute("user",user);

        if(user != null){
            request.getRequestDispatcher("/client/Index.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("/client/Login.jsp").forward(request,response);
        }
    }
}
